home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Telnet 2.7b5 / source / ICR / vdevice.c next >
Encoding:
Text File  |  1995-04-18  |  2.2 KB  |  104 lines  |  [TEXT/CWIE]

  1. //vdevice.c
  2.  
  3. #include "vdevice.h"
  4. #include "vdevice.proto.h"
  5. #define PIXEL_DEPTH 8
  6. CGrafPtr origPort;
  7. GDHandle origDev;
  8.  
  9.  
  10. int InitVDevice (VDevicePtr whichDevice, PaletteHandle initalPalette)
  11.  
  12. {
  13.     
  14.     PixMapHandle thePixMap;
  15.     OSErr err;
  16.     CTabHandle theNewColorTable;
  17.     
  18.     GetGWorld(&origPort,&origDev); //save old settings
  19.     
  20.     //first, copy the initalPalette into a color table handle
  21.     
  22.     theNewColorTable = (CTabHandle) myNewHandle(sizeof(ColorTable));
  23.     if (!theNewColorTable)
  24.         return -1;
  25.     Palette2CTab(initalPalette,theNewColorTable);
  26.     
  27.     //init the GWorld
  28.     err = NewGWorld(&whichDevice->whichWorld,PIXEL_DEPTH,whichDevice->bounds,
  29.                     theNewColorTable,NULL,0);
  30.     
  31.     if ((!whichDevice->whichWorld)||(err != noErr))
  32.     {
  33.         if (whichDevice->whichWorld)
  34.             DisposeGWorld(whichDevice->whichWorld);
  35.             DisposeHandle((Handle)theNewColorTable);
  36.             return -1;
  37.     }
  38.     SetGWorld(whichDevice->whichWorld,NULL);
  39.     thePixMap = GetGWorldPixMap(whichDevice->whichWorld);
  40.     EraseRect(&(whichDevice->whichWorld->portRect));
  41.     SetGWorld(origPort,origDev);
  42.     return (0);
  43. }
  44.     
  45.     
  46.     
  47. void ColorVDevice
  48.   (
  49.     VDevicePtr vdev,
  50.     PaletteHandle pal
  51.   )
  52. {
  53.     CTabHandle ct;
  54.  
  55.     ct = (*vdev->whichWorld->portPixMap)->pmTable;        /* handle from vdevice */
  56.     if (!ct)
  57.         return;
  58.     
  59.     Palette2CTab( pal, ct );
  60.  
  61.     (*ct)->ctSeed = GetCTSeed();                    /* give it a unique seed */
  62.     (*ct)->ctFlags = 0x8000;
  63.     
  64.     //MakeITable( ct, (vdev->whichWorld->gdITable, 3 );    /* 3-bit inverse table  */
  65.  
  66. }
  67.  
  68. /*******************************************************************************/
  69. /* SetVDevice
  70. *  Set the gdevice and port to our off-screen space.
  71. *  Save the old values for unset.
  72. */
  73. SetVDevice(VDevicePtr vdev)
  74. {
  75.  
  76.     GetGWorld(&origPort,&origDev); //save old settings
  77.     if (!vdev->whichWorld)
  78.         return(-1);
  79.     SetGWorld(vdev->whichWorld,NULL);
  80.     return(0);
  81. }
  82.  
  83. /*******************************************************************************/
  84. /* UnsetVDevice
  85. *  Set the vdevice back to the saved values.
  86. */
  87. void    UnsetVDevice(void)
  88. {
  89.     SetGWorld(origPort,origDev);
  90. }
  91.  
  92. /*******************************************************************************/
  93. /* TrashVDevice
  94. *  Get rid of the devices that we created with InitVDevice.
  95. */
  96. void TrashVDevice(VDevicePtr vdev)
  97. {
  98.     if (vdev->whichWorld)
  99.         DisposeGWorld(vdev->whichWorld);
  100.     return;
  101. }
  102.  
  103.  
  104.